function TreeNode(val) {
    this.val = val;
    this.left = null;
    this.right = null;
}

// 简单二叉树
const tree1 = new TreeNode(1);
tree1.left = new TreeNode(2);
tree1.right = new TreeNode(3);

// 不平衡二叉树
const tree2 = new TreeNode(10);
tree2.left = new TreeNode(5);
tree2.left.left = new TreeNode(2);
tree2.left.left.left = new TreeNode(1);

// 完全二叉树
const tree3 = new TreeNode(1);
tree3.left = new TreeNode(2);
tree3.right = new TreeNode(3);
tree3.left.left = new TreeNode(4);
tree3.left.right = new TreeNode(5);
tree3.right.left = new TreeNode(6);

function midorder(root) {
    let out = [];
    if (!root) return out;
    out.push(...midorder(root.left));
    out.push(root.val);
    out.push(...midorder(root.right));
    return out;
}

console.log(midorder(tree1));
